{include file="/common/header"}
    <style type="text/css">
        .geetest_holder.geetest_wind { width: 100%!important; }
    </style>
    <div class="container">
        <div class="row">
            <div class="col-md-6 col-sm-6 col-1g-6 reg">
                <div class="lk-panel">
                    <h1 class="text-center">注册</h1>
                    <form class="layui-form" action="" method="post">
                        <div class="layui-form-item">
                            <input type="email" name="email" required lay-verify="required" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-item">
                            <input type="text" name="username" required lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-item">
                            <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-item">
                            <input type="password" name="passwords" required lay-verify="required" placeholder="请输入确认密码" autocomplete="off" class="layui-input">
                        </div>
                        {if condition="!$conf.reg_close"}
                        <div class="layui-form-item">
                            <div id="embed-captcha"></div>
                            <p id="wait">正在加载验证码......</p>
                        </div>
                        {/if}
                        <div class="layui-form-item">
                            <button class="layui-btn btn-block" id="sign-up" lay-submit="" lay-filter="sign-up"{if condition="$conf.reg_close"} disabled>已关闭注册{else /}>注册{/if}</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
<script type="text/javascript" src="_js_gt.js"></script>
<script type="text/javascript">
    layui.use('form', function() {
        var form = layui.form;
        $.ajax({
            // 获取id，challenge，success（是否启用failback）
            url: "/reg/gtStartCaptchaServlet",
            type: "post",
            data: {'t': (new Date()).getTime()},
            dataType: "json",
            success: function (data) {
                // 使用initGeetest接口
                // 参数1：配置参数
                // 参数2：回调，回调的第一个参数验证码对象，之后可以使用它做appendTo之类的事件
                initGeetest({
                    gt: data.gt,
                    challenge: data.challenge,
                    new_captcha: data.new_captcha,
                    protocol: 'https://',
                    product: "popup", // 产品形式，包括：float，embed，popup。注意只对PC版验证码有效
                    offline: !data.success // 表示用户后台检测极验服务器是否宕机，一般不需要关注
                }, handlerEmbed);
            }
        });
        //监听提交
        var handlerEmbed = function (captchaObj) {
            form.on('submit(sign-up)', function(data) {
                var validate = captchaObj.getValidate();
                if (!validate) {
                    layer.msg('请完成验证', function() {});
                    return false;
                } else {
                    btnLoad('#sign-up', '注册中...');
                    $.post('', data.field, function(res) {
                        closeBtnLoad('#sign-up', '注册');
                        if(res.code) {
                            return layer.alert('注册成功', {icon: 1}, function (index) {
                                layer.close(index);
                                window.location.href = '/login';
                            });
                        }
                        return layer.alert(res.msg, {icon: 2});
                    });
                }
                return false;
            });
            // 将验证码加到id为captcha的元素里，同时会有三个input的值：geetest_challenge, geetest_validate, geetest_seccode
            captchaObj.appendTo("#embed-captcha");
            // 验证码加载完成
            captchaObj.onReady(function () {
                $("#wait").hide();
            });
        };
    });
</script>

{include file="/common/footer"}